package com.example.dynamicschedule.service.impl;

import com.example.dynamicschedule.bean.CkFeedbackTable;
import com.example.dynamicschedule.dao.CkFeedbackTableMapper;
import com.example.dynamicschedule.service.CkFeedBackService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CkFeedBackServiceImpl implements CkFeedBackService {

    private  static final Logger logger = LoggerFactory.getLogger(CkFeedBackServiceImpl.class);

    @Autowired
    private CkFeedbackTableMapper ckFeedbackTableMapper;
    static Date date = new Date();
    static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    static String format = simpleDateFormat.format(date);
    @Override
    public void insert(CkFeedbackTable ckFeedbackTable) {
        ckFeedbackTable.setUpdateTime(format);
        ckFeedbackTableMapper.insert(ckFeedbackTable);
    }

    @Override
    public void updateByPrimaryKey(CkFeedbackTable ckFeedbackTable) {
        ckFeedbackTable.setUpdateTime(format);
        ckFeedbackTableMapper.updateByPrimaryKey(ckFeedbackTable);
    }

    @Override
    public void deleteByPrimaryKey(Long id) {
        ckFeedbackTableMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<CkFeedbackTable> selectList() {

        return ckFeedbackTableMapper.selectList();
    }

    @Override
    public String selectByChinese(String chinese) {
        return ckFeedbackTableMapper.selectByChinese(chinese);
    }


    @Override
    public Map<String, Object> selectCkFeedbackByType() {
        logger.info("查询失联原因和停催原因   无参数");
        //停催原因
        List<CkFeedbackTable> tcFeedBack = ckFeedbackTableMapper.selectCkFeedbackByType((byte) 1);
        //失联原因
        List<CkFeedbackTable> slFeedBack = ckFeedbackTableMapper.selectCkFeedbackByType((byte) 2);

        Map<String, Object> data = new HashMap<>();
        data.put("tcFeedBack",tcFeedBack);
        data.put("slFeedBack",slFeedBack);
        logger.info("查询失联原因和停催原因 data结果==" + data.toString());
        return data;
    }
}
